import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import Detail from '@/views/Detail/index.vue'
import Register from '@/views/Login/components/Register.vue'
import CartList from '@/views/CartList/index.vue'
import CheckOut from '@/views/CheckOut/index.vue'
import Pay from '@/views/Pay/index.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // path和component对应关系的位置
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          //默认渲染页，当我们访问/时，Home也会被渲染
          path: '',
          component: Home
        },
        {
          path: 'Category',
          component: Category
        },
        {
          path: 'detail/:id',
          component: Detail
        },
        {
          path: 'CartList',
          component: CartList
        },
        {
          path: 'CheckOut',
          component: CheckOut
        }
        ,
        {
          path: 'Pay',
          component: Pay
        }
      ]
    },
    {
      path: '/Login',
      component: Login
    },
    {
      path: '/Register',
      component: Register
    }
  ],
   // 路由滚动行为定制
  scrollBehavior () {
    return {
      top: 0
    }
  }
})

export default router
